package dao.impl;

import dao.LoginDao;
import domain.Student;
import util.JdbcUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class LoginDaoImpl implements LoginDao {
    @Override
    public Student getStudentsByStudent_id(String studentId) throws SQLException {
        Connection conn = JdbcUtils.getConnection();
        String sql = "select * from student where student_id = ?";
        PreparedStatement preparedStatement = conn.prepareStatement(sql);
        preparedStatement.setString(1, studentId);

        ResultSet rs = preparedStatement.executeQuery();
        Student student = null;
         while (rs.next()) {
            student = new Student(
                    rs.getInt("id"),
                    rs.getString("student_name"),
                    rs.getString("student_id"),
                    rs.getString("student_password"),
                    rs.getInt("major_id"),
                    rs.getInt("class_id")
            );
        }

        preparedStatement.close();
        conn.close();
        return student;
    }



}
